package World;

import Entities.World;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;

public class FileWorldListLoader implements WorldListLoader {

    private String path = "C:/WorldList/";

    @Override
    public ArrayList<World> loadWorldList() {
        try {
            ArrayList<World> worldList = new ArrayList<World>();
            File file = new File(path);

            for (int i = 0; i < file.list().length; i++) {
                File file2 = new File(path + i + "/worldDescriptor.txt");
                FileInputStream fileInputStream = new FileInputStream(file2);
                ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
                worldList.add((World) objectInputStream.readObject());
            }
            return worldList;
        } catch (Exception e) {
        }
        return null;
    }
}
